package SPH;
public class Vector3D {
	public float x;
	public float y;
	public float z;
	public float p;
	
	/**Default Constructor
	 */
	public Vector3D(){
		this.x = 0;
		this.y = 0;
		this.z = 0;
		this.p = 0;
	}
	/** Constructor 
	 * @param x
	 * @param y
	 * @param z
	 */
	public Vector3D(float x, float y, float z){
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vector3D(float x, float y, float z, float p){
		this.x = x;
		this.y = y;
		this.z = z;
		this.p = p;
	}
	
	/** Summation of two vectors 
	 * @param v1
	 * @param v2
	 * @return vector 
	 */
	public static Vector3D addition(Vector3D v1, Vector3D v2){
		return new Vector3D(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
	}
	
	
	/**Subtraction of two vectors
	 * @param v1
	 * @param v2
	 * @return Vector3D
	 */
	public static Vector3D subtraction(Vector3D v1, Vector3D v2){
		return new Vector3D(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
	}
	/** Multiplicate vector on scalar
	 * @param v
	 * @param scalar
	 * @return
	 */
	public static Vector3D mutiplicationOnScalar(Vector3D v, float scalar){
		return new Vector3D(v.x * scalar, v.y * scalar, v.z * scalar);
	}
	
	/** Copy coordinates of one vector to current
	 * @param v
	 */
	public void copy(Vector3D v){
		this.x = v.x;
		this.y = v.y;
		this.z = v.z;
	}
	
	/**Get length of vector
	 * @return 
	 */
	public double length(){
		return Math.sqrt(x*x + y*y + z*z);
	}
	/**
	 * Normalizes this Vector3D that its direction remains the same but its length is 1.
	 */
	public void unitize(){
		double len = this.length();
		if (len == 0)
			return;
		x /= len;
		y /= len;
		z /= len;
	}
	/** Scalar multiplication of two vectors
	 * @param v
	 * @return double value
	 */
	public double scalarMultiplication(Vector3D v){
		return this.x * v.x + this.y * v.y + this.z * v.z;
	}
	
}
